<template>
  <div>
        <div class="title_box">
          <div class="iconfont icon-left" @click="$router.go(-1)"></div>
          <div class="title"></div>
          <div class="iconfont icon-gouwuche" @click="$router.push('/shoppingCar')"></div>
        </div>
        <div class="occupy"></div>

      <div class="goodsList" v-if="show">
        <!-- <div class="tilte">猜你喜欢</div> -->
        <div class="guessLike" v-for="(item,index) in goodslist" :key="index" @click="goDetails(item.goods_id)">
            <div class="item">
              <div class="imgs">
                <img :src="item.goods_small_logo"/>
              </div>
              <div class="text">
                <div class="name">
                    {{ item.goods_name }}
                    </div>
                <div class="priceBox">
                  <div class="price">
                      {{ item.goods_price }}
                  </div>
                  <div class="iconfont icon-shoucang">{{ Math.floor((Math.random()*100)+1) }}</div>
                </div>
              </div>
            </div>
        </div>
      </div>
      <div class="default" v-else>暂无该商品，搜索其他试试吧~</div>
  </div>
</template>

<script>
import axios from "axios"
export default {
    data() {
        return {
            goodslist:[], //
            show: true
        }
    },
    methods:{
         api(){
            return "https://api-hmugo-web.itheima.net/api/public/v1/goods/search?query=";
        },
        getGoodsdata(){
            axios.get(this.api() + this.$route.query.name).then(data=>{
               let goods = data.data.message.goods
               if(goods.length == 0){
                   this.show = false
               }
                this.goodslist = goods.filter(item=>{
                    return item.goods_small_logo != ""
                })
            })
        },
        goDetails(id){
            this.$router.push({name:'Details',query: {goods_id:id}})
        }
    },
    created(){
        this.getGoodsdata()
    }
}
</script>


<style lang="less" scoped>
.default{
    text-align: center;
    margin-top: 100px;
}
.goodsList{
  .tilte {
    text-align: center;
    position: relative;
    &::before,
    &::after{
      display: block;
      content: "";
      width: 100px;
      height: 2px;
      background: #cccccc;
      position: absolute;
      top: 20px;
    }
    &::before{
      left: 200px;
    }
    &::after{
      right: 200px;
    }
  }
  .guessLike {
    width: 50%;
    float: left;
    overflow: hidden;
    .item{
      width: 96%;
      margin: 20px auto;
      background: #fff;
      .imgs img{
        width: 100%;
        height: 396px;
      }
      .text{
        padding: 10px;
        .name{
          height: 56px;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
          font-size: 20px;
          color: #333;
          /* text-overflow: ellipsis;
          white-space: nowrap;
          overflow: hidden; */
        }
        .priceBox{
          display: flex;
          justify-content: space-between;
          // height: 80px;
          // line-height: 80px; 
          padding: 10px 0;
          .price{ 
            line-height: 42px;
            float: left;
            font-size: 26px;
            font-weight: bold;
            color: #FF4466;
            position: relative;
            padding-left: 10px;
            &::before{
                display: block;
                content: "￥";
                position: absolute;
                left: -6px;
                top: 2px;
                font-size: 18px;
                font-weight: bolder;
            }
          }
          .iconfont{
            color: #666;
            font-size: 22px;
            line-height: 42px;
          }
        }
      }
    }
  }
}

.occupy{
  width: 100%;
  height: 74px;
}
.title_box {
  position: fixed;
  width: 100%;
  height: 60px;
  line-height: 60px;
  padding: 7px 0px;
  text-align: center;
  background: #fff;
  border-bottom: 1px solid #E8E8E8;
  display: flex;
  justify-content: space-around;
  color: #666;
  div:nth-child(odd){
      flex: 1;
      font-size: 36px;

  }
  .title {
    flex: 6;
    font-size: 34px;
  }
}

</style>
